﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include <vector>
#include "GDFoundation/IParameterDisplayListRegister.h"
#include <set>
#include "IElement.h"
#include "IMenuItemContainerDefinition.h"

#ifdef Sample_UiAdapter_EXPORTS
#define UIADAPTER_API __declspec(dllexport)
#else
#define UIADAPTER_API __declspec(dllimport)
#endif

namespace gcmp
{
    class IPickEventHandler;
    class ActionModifyInput;
    class IDocument;
    class IElement;
    class UniIdentity;
    class IParameter;
}
namespace Sample
{
    //应用程序环境应该提供扩展默认命令右键菜单的机制
    //这里通过提供策略+注册的方式来演示右键菜单的添加
    class UIADAPTER_API IElementContextMenuStrategy
    {
    public:
        virtual ~IElementContextMenuStrategy() = default;
        virtual bool AppendContextMenu(gcmp::IElement* pElement, gcmp::IMenuItemContainerDefinition* pMenuItemContainer) const = 0;
        virtual bool AppendContextMenu(std::unordered_set<gcmp::IElement*> elements, gcmp::IMenuItemContainerDefinition* pMenuItemContainer) const {
            return false;
        }
    };

    //组件正常运行时需要和应用程序相关交互/界面来适配
    //譬如属性面板、默认命令的扩展方式等等
    class UIADAPTER_API UiAdapter {
    public:
        //获取参数下拉列表注册器，用来给组件注册到属性面板使用
        static gdmp::IParameterDisplayListRegister* GetDisplayListRegister();
        static void SetDisplayListRegister(gcmp::OwnerPtr<gdmp::IParameterDisplayListRegister> opObject);
        static void RegisterContextMenuStrategy(gcmp::OwnerPtr<Sample::IElementContextMenuStrategy> opObject);
        static void ApplyContextMenuStrategy(gcmp::IDocument* pDocument, gcmp::ElementId elementId, gcmp::IMenuItemContainerDefinition* pMenuItemContainer);
    
        static void SetActionModifyAddEventHandlerCallBack(std::function<void(gcmp::ActionModifyInput& input)> func);
        static void ApplyPickPostProcessEventHandler(gcmp::ActionModifyInput& input);
    

    public:
        // 属性面板相关
        static bool GetPresetValuesGroupId(const gcmp::IDocument* pDocument, const gcmp::IElement* pElement, Int32& groupId);

        static bool SetPresetParameter(const gcmp::IDocument* pDocument, const gcmp::UniIdentity& categoryUid, Int32 presetValuesGroupId, const gcmp::IParameter* pParameter);
    private:
        class Impl;
        static Impl& Get();

        class Modifyer;
        static Modifyer& GetModifyer();
    };
}
